(()=> {
	const buildList = [
		{
			name: '爱森堡',
			id: 1
		},
		{
			name: '花街区',
			id: 2
		},
		{
			name: '蓝郡邸',
			id: 3
		},
		{
			name: '时代城',
			id: 4
		},
		{
			name: '甜心镇',
			id: 5
		},
		{
			name: '世豪庭',
			id: 6
		},
		{
			name: '锦绣苑',
			id: 7
		},
		{
			name: '塞纳畔',
			id: 8
		}
	]
	
	
	let ele = {};
	ele.optionList = $('#optionList');
	ele.optionin = $('#optionin');
	ele.jilu = $('#jilu');
	ele.more = $('#more');
	ele.empty = $('#empty');
	ele.jitit = $('#jitit');
	
	// console.log(11);
	getWerewolfLog()
	// 获取往期记录
	function getWerewolfLog(){
	    let token = getCookie("token");
	    ajax({
			url: API_PATH.GET_WEREWOLF_LOG,
			method: 'GET',
			header: {
				'Authorization': token
			},
			success: res => {
				if (res.code == 1) {
					drawListHundred(res.data.hundred)
					drawListShi(res.data.ten)
				}
			}
		});
	}
	
	function drawListHundred(data) {
		let html = '';
		for(let i = 0; i < data.length; i++) {
			html += `<div class="optionin">
						<span>${buildList[i].name}</span>
						<img src="http://img.qxgs.cc/tiantianlaishouzu/img/battle/MG_XT.png" alt="">
						<p class="solute">${data[i]}</p>
					</div>`
		}
		ele.optionList.innerHTML = html;
	}
	
	function drawListShi(data) {
		console.log(data.length);
		let html = '';
		for(let i = 0; i < data.length; i++) {
			html += `<div class="optionin">
						<span>${data[i].building_str}</span>
						<p>第${data[i].phase}期</p>
					</div>`
		}
		ele.optionin.innerHTML = html;
	}
	
	let page = 1;
	getWerewolfJoinLog(page)
	// 获取参与记录
	function getWerewolfJoinLog(page){
	    let token = getCookie("token");
	    ajax({
			url: API_PATH.GET_WEREWOLF_JOIN_LOG,
			method: 'GET',
			header: {
				'Authorization': token
			},
			data: {
				page: page
			},
			success: res => {
				if (res.code == 1) {
					let detail = res.data.data;
					if (detail.length === 0) {
						page = 0;
						ele.more.style.display = "none";
						ele.empty.style.display = "flex";
						ele.jitit.style.display = "none";
					} else {
						drawDetail(detail);
						page++;
						if (page > res.data.last_page) {
							ele.jitit.style.display = "flex";
							ele.more.innerText = '没有更多了';
							ele.more.onclick = null;
						}
						else {
							ele.jitit.style.display = "flex";
							ele.more.innerText = '加载更多';
							ele.more.onclick = () => getDetail(page);
						}
					}
				} else openTips(res.msg);
			}
		});
	}
	
	function drawDetail(data) {
		if (data.length === 0) {
			page = 0;
			ele.more.style.display = "none";
			ele.empty.style.display = "flex";
			ele.jitit.style.display = "none";
		} else {
			let str = '';
			for (let i = 0; i < data.length; i++) {
				let sign = data[i].operation_type == 1 ? '+' : '-';
				let resume = '';
				if(data[i].status  == 2) {
					resume = '<p>本局流局</p>';
				} else {
					resume = '<img src="http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi.png" alt=""><p>'+data[i].profit+'</p>';
				}
				str += `<div class="jixai">
							<p>${data[i].phase}</p>
							<div class="">
								<img src="http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi.png" alt="">
								<p>${data[i].invest_num}</p>
								<span>${buildList[parseInt(data[i].building_id) - 1].name}</span>
							</div>
							<div class="">
								${resume}
							</div>
						</div>`;
			}
			ele.jilu.innerHTML += str;
		}
	}
})()